#include "lcd.h"

void init_Lcd()
{
	write_cmd(0x38);
	write_cmd(0x0c);
	write_cmd(0x06);
	write_cmd(0x01);
}

void wait()
{
	P0=0xff;
	do
	{
		EN=0;
		RS=0;
		RW=1;
		EN=1;
	}while(BUSY);
	EN=0;
}

void write_byte(uint8 dat)
{
	wait();
	EN=0;
	RS=1;
	RW=0;
	P0=dat;
	EN=1;
	EN=0;
}

void write_String(uint8 address,uint8 *p)
{
	write_cmd(address);
	while(*p!='\0')
	{
		write_byte(*p++);
	}
}

void write_Num(uint8 num)
{
	if(num/100%10>0){
		write_byte(num/100%10+'0');
	}
	if(num/10%10>0||num/100%10>0){
		write_byte(num/10%10+'0');
	}
	write_byte(num%10+'0');
}

void write_cmd(uint8 cmd)
{
	wait();
	EN=0;
	RS=0;
	RW=0;
	P0=cmd;
	EN=1;
	EN=0;
}
